﻿using System;
using System.Collections.Generic;
using JLL.China.Infrastructure.Repositories;
using JLL.China.Infrastructure.Repositories.Listings;
using JLL.China.Infrastructure.RepositoryFramework;
using JLL.China.Infrastructure.UnitOfWork;
using JLL.China.Model;
using JLL.China.Model.DTO;
namespace JLL.China.Infrastructure.Services
{
    public static class ListingService
    {
        private static ListingsRepository _repository;

        static  ListingService()
        {
           _repository = RepositoryFactory.GetRepository<ListingsRepository,Model.Listings,int>(new LINQ2SQLUnitOfWork<int>());
        }

        public static int  Store(Listings item)
        {
            return _repository.Post(item);
        }
        public static void ChangeStatus(string arrayId,int status)
        {
            _repository.ChangeStatus(arrayId,status);
        }
        public static void Save()
        {
            _repository.UnitOfWork.Commit();
        }

        public static IList<Model.Listings> Search(ListingSearchCriteria searchCriteria)
        {
            return _repository.Search(searchCriteria);
        }
        public static Model.Listings FindById(int ID)
        {
            return _repository.FindById(ID);
        }
        public static Model.Listings FindBy(int ID)
        {
            return _repository.FindBy(ID);
        }
        public static void Update(Model.Listings item)
        {
            var listing = _repository.FindBy(item.ID);
            if(listing != null){
                listing.Latitude = item.Latitude;
                listing.Longitude = item.Longitude;
                
            }
            _repository[listing.ID] = listing;
        }

        public static void UpdateStep2(Model.ListingDetail item)
        {
            _repository.SaveDetail(item);
        }
        public static ListingDetail GetProjectDirDetail(int id, int lang)
        {
            return _repository.GetDetail(id, lang);
        }
        public static void UpdateStep3(int id, string features, string facilities)
        {
            _repository.UpdateFacilitiesFeatures(id, features, facilities);
        }
    }
}
